package com.cdks.wuxiu.api.controller;

import com.cdks.wuxiu.api.model.common.AuthParam;
import com.cdks.wuxiu.api.model.dto.KmsgDataDTO;
import com.cdks.wuxiu.api.model.param.AuthGetCallTokenParam;
import com.cdks.wuxiu.api.model.param.AuthGetUserTokenParam;
import com.cdks.wuxiu.api.model.vo.AuthGetCallTokenVO;
import com.cdks.wuxiu.api.model.vo.AuthGetKmsgTokenVO;
import com.cdks.wuxiu.api.model.vo.AuthGetUserTokenVO;
import com.cdks.wuxiu.api.service.AuthService;
import com.cdks.wuxiu.common.model.api.ApiResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;


@Api(tags = "授权接口")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private AuthService authService;


    @ApiOperation("置换用户token")
    @PostMapping("/getUserToken")
    public ApiResult<AuthGetUserTokenVO> getUserToken(@RequestBody @Valid AuthGetUserTokenParam param) {
        AuthGetUserTokenVO vo  = new AuthGetUserTokenVO();
        vo.setToken(authService.getUserToken(param.getUserId(), param.getNonce(), param.getChalln()));
        
        return ApiResult.success(vo);
    }

    @ApiOperation("获取消息token")
    @PostMapping("/getKmsgToken")
    public ApiResult<AuthGetKmsgTokenVO> getKmsgToken(@RequestBody @Valid AuthParam param) {
        AuthGetKmsgTokenVO vo  = new AuthGetKmsgTokenVO();
        KmsgDataDTO data  = authService.getKmsgData(param.getUserId());
        vo.setToken(data.getToken());
        
        return ApiResult.success(vo);
    }

    @ApiOperation("获取通话token")
    @PostMapping("/getCallToken")
    public ApiResult<AuthGetCallTokenVO> getCallToken(@RequestBody @Valid AuthGetCallTokenParam param) {
        AuthGetCallTokenVO vo  = new AuthGetCallTokenVO();
        vo.setCallToken(authService.getCallToken(param.getUserId(), param.getUcid()));
        
        return ApiResult.success(vo);
    }
}
